package com.ynet.middleground.riskmanage.mq.producer;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import com.ynet.core.log.IfpLogger;
import com.ynet.middleground.riskmanage.mq.SourceBlch;

/**
 * @author liulx
 * @description 中台需要推送的保理池数据
 * @date 2020-08-20 17:00
 */
@EnableBinding({SourceBlch.class})
@Component
public class BlchProducer {

    @Autowired
    private SourceBlch sourceBlch;

    /**
     * 给核心系统 MQ 推送入池数据
     *
     * @param data 推送入池信息
     */
    public void sendMessagesBlchIn(Map<String, Object> data) {
        IfpLogger.info("mq", "MQ 推送入池数据给核心系统，往 Binding-{} 推送信息-{}", SourceBlch.OUT_RISKMANAGE, data);
        Map<String, Object> headers = new HashMap<>(1);
        // tags 标签对应 yml 配置文件
        headers.put("TAGS", "in");
        MessageHeaders messageHeaders = new MessageHeaders(headers);
        Message<Map<String, Object>> message = MessageBuilder.createMessage(data, messageHeaders);
        this.sourceBlch.notice().send(message);
    }

    /**
     * 给核心系统 MQ 推送出池数据
     *
     * @param data 推送出池信息
     */
    public void sendMessagesBlchOut(Map<String, Object> data) {
        IfpLogger.info("mq", "MQ 推送出池数据给核心系统，往 Binding-{} 推送信息-{}", SourceBlch.OUT_RISKMANAGE, data);
        Map<String, Object> headers = new HashMap<>(1);
        // tags 标签对应 yml 配置文件
        headers.put("TAGS", "out");
        MessageHeaders messageHeaders = new MessageHeaders(headers);
        Message<Map<String, Object>> message = MessageBuilder.createMessage(data, messageHeaders);
        this.sourceBlch.notice().send(message);
    }

}
